package com.cx.controller.wjj;

import com.cx.pojo.PageDelivery;
import com.cx.pojo.Site;
import com.cx.pojo.wjj.Start2Destination;
import com.cx.service.wjj.MapService;
import com.cx.util.wjj.AddressUtil;
import com.cx.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("map")
public class MapController {
    @Autowired
    MapService mapService;

    @RequestMapping("selectStart2Destination")
    public ResponseResult selectStart2Destination(ResponseResult responseResult,Integer pageNum){
         Start2Destination start2Destination =new Start2Destination();
         PageDelivery pageDelivery =  mapService.selectByPageNum(pageNum);
         if(null!=pageDelivery) {
             StringBuilder start = new StringBuilder();
             start.append(pageDelivery.getStartProvince()).append(pageDelivery.getStartCity()).append(pageDelivery.getStartArea());
             StringBuilder route=new StringBuilder();
             route.append(pageDelivery.getNowProvince()).append(pageDelivery.getNowCity()).append(pageDelivery.getNowArea());
             StringBuilder end =new StringBuilder();
             end.append(pageDelivery.getEndProvince()).append(pageDelivery.getEndCity()).append(pageDelivery.getEndArea());
             String startAddress = start.toString();
             String routeAddress=route.toString();
             String endAddress=end.toString();
             start2Destination = AddressUtil.address2LonLat(pageNum,startAddress,routeAddress,endAddress);
             responseResult.setCode(1);
             responseResult.setMessage("查询成功");
             responseResult.setData(start2Destination);

         }else {
             responseResult.setCode(0);
             responseResult.setMessage("查询失败");
         }
        System.out.println(responseResult);
        return responseResult;
    }


    @RequestMapping("selectAllSite")
    public ResponseResult selectAllSite(ResponseResult responseResult){
      List<Site> siteList =  mapService.selectAllSite();
        if(null!=siteList&&siteList.size()>0){
           List<String> list = new ArrayList<>();
           String province=null;
           String city=null;
           String area=null;
            for (int i = 0; i < siteList.size(); i++) {
                province = siteList.get(i).getSiteProvince();
                city = siteList.get(i).getSiteCity();
                area =siteList.get(i).getSiteArea();
                String addressLonLat=AddressUtil.characters2LonLat(province,city,area);
                list.add(addressLonLat);
            }
            responseResult.setCode(1);
            responseResult.setMessage("查询成功");
            responseResult.setData(list);
        }else {
            responseResult.setCode(0);
            responseResult.setMessage("查询失败");
        }

        return responseResult;
    }


}
